package org.jeecg.modules.test.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.jeecg.api.params.HeightLevelUserParams;
import org.jeecg.api.query.HeightLevelUserQuery;
import org.jeecg.api.vo.HeightLevelUserVO;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.test.entity.HeightLevelUser;
import org.jeecg.modules.test.service.IHeightLevelUserService;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.annotation.Resource;

/**
 * @author ZhangYu
 * @date 2023/9/24 23:45
 * @description 测试用户
 */
@Api(tags = "测试用户")
@RestController
@RequestMapping("/height/level/user")
public class HeightLevelUserController extends JeecgController<HeightLevelUser, IHeightLevelUserService> {

    @Resource
    private IHeightLevelUserService heightLevelUserService;

    /**
     * 查询用户分页
     *
     * @param heightLevelUserQuery 用户查询条件
     * @return 用户分页
     */
    @ApiOperation("查询用户分页")
    @GetMapping("/select/user/page")
    public Result<?> selectUserPage(HeightLevelUserQuery heightLevelUserQuery) {
        Page<HeightLevelUserVO> heightLevelUserPage = heightLevelUserService.selectUserPage(heightLevelUserQuery);
        return Result.OK(heightLevelUserPage);
    }

    /**
     * 新增用户
     *
     * @param heightLevelUserParams 用户新增or修改参数
     * @return 新增信息
     */
    @ApiOperation("新增用户")
    @PostMapping("/add/user")
    public Result<?> addUser(@RequestBody HeightLevelUserParams heightLevelUserParams) {
        heightLevelUserService.addUser(heightLevelUserParams);
        return Result.OK();
    }

    /**
     * 删除用户
     *
     * @param id 主键
     * @return 删除信息
     */
    @ApiOperation("删除用户")
    @DeleteMapping("/delete/by/id")
    public Result<?> deleteById(@RequestParam Long id) {
        heightLevelUserService.deleteById(id);
        return Result.OK();
    }

    /**
     * redis添加and查询
     *
     * @param test 加入参数
     * @return redis值
     */
    @ApiOperation("redis添加and查询")
    @GetMapping("/redis/add/find")
    public Result<?> redisAddFind(String test) {
        String testValue = heightLevelUserService.redisAddFind(test);
        return Result.OK(testValue);
    }

    /**
     * lambda测试
     *
     * @return 测试结果
     */
    @ApiOperation("lambda测试")
    @GetMapping("/lambda/test")
    public Result<?> lambdaTest() {
        heightLevelUserService.lambdaTest();
        return Result.OK();
    }

    /**
     * 添加大量数据
     *
     * @return 添加信息
     */
    @ApiOperation("添加大量数据")
    @GetMapping("/add/big/data")
    public Result<?> addBigData() {
        heightLevelUserService.addBigData();
        return Result.OK();
    }

    /**
     * 远程调用测试
     *
     * @return 测试信息
     */
    @ApiOperation("远程调用测试")
    @GetMapping("/long/range/test")
    public Result<?> longRangeTest() {
        heightLevelUserService.longRangeTest();
        return Result.OK();
    }

    /**
     * 测试synchronized
     *
     * @param id 用户id
     * @return 测试信息
     */
    @ApiOperation("测试synchronized")
    @GetMapping("/test/synchronized/{id}")
    public Result<?> testSynchronized(@PathVariable Long id) {
        heightLevelUserService.testSynchronized(id);
        return Result.OK();
    }

    /**
     * 测试reentrantLock
     *
     * @param id 用户id
     * @return 测试信息
     */
    @ApiOperation("测试reentrantLock")
    @GetMapping("/test/reentrantLock/{id}")
    public Result<?> testReentrantLock(@PathVariable Long id) {
        heightLevelUserService.testReentrantLock(id);
        return Result.OK();
    }

    /**
     * 测试Elasticsearch数据分页查询
     *
     * @param pageNo   当前页码
     * @param pageSize 每页条数
     * @return 同步信息
     */
    @ApiOperation("测试Elasticsearch数据同步")
    @GetMapping("/test/elasticsearch/page")
    public Result<Page<HeightLevelUserVO>> testElasticsearchPage(@RequestParam Integer pageNo, @RequestParam Integer pageSize) {
        Page<HeightLevelUserVO> heightLevelUserPage = heightLevelUserService.testElasticsearchPage(pageNo, pageSize);
        return Result.OK(heightLevelUserPage);
    }

}
